package com.example.stockservice.service;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StockService {

    private static final Map<String, List<StockRecord>> stockRecordMap = new HashMap<>();

    public Boolean recordDeduct(String productId, Integer count) {
        // 记录库存扣减日志
        List<StockRecord> records = stockRecordMap.computeIfAbsent(productId, k -> new ArrayList<>());
        records.add(new StockRecord(System.currentTimeMillis(), "DEDUCT", count));
        return true;
    }

    static class StockRecord {
        private long timestamp;
        private String type;
        private Integer count;

        public StockRecord(long timestamp, String type, Integer count) {
            this.timestamp = timestamp;
            this.type = type;
            this.count = count;
        }

        // getters and setters
        public long getTimestamp() {
            return timestamp;
        }

        public void setTimestamp(long timestamp) {
            this.timestamp = timestamp;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public Integer getCount() {
            return count;
        }

        public void setCount(Integer count) {
            this.count = count;
        }
    }
}
    